﻿
var tableName = '';
var menuID = '';
var dateStandartFormat = 'Y-m-d';
window.onerror = ErrorScriptInPage;
function ErrorScriptInPage(message, url, linenumber) {
    Ext.Ajax.request({
        url: 'error.aspx',
        //method: 'POST',
        headers: {
            'my-header': 'Script Error'
        },
        params: { name: window.name, line: linenumber, msg: message, url: url }
    });
}

function GetWorkingDate() {
    return window.parent.dfWorkingDate.getValue();
}
function SetFocusFirstLookup(wnd) {
    var iframmain = document.getElementById(wnd.iframe.id);
    if (iframmain != 'undefined' && typeof (iframmain.contentWindow.FocusFirst) != 'undefined')
        setTimeout(function() { iframmain.contentWindow.FocusFirst(); }, 100);
}
Number.prototype.toMoney = function() {
    return formatMoney(this);
}

function removeThousandsSeparator(value) {
    if (isNaN(value)) {
        var decimals = '2';
        var decimal_sep = ',';
        var thousands_sep = '.';
        if (window.navigator.systemLanguage == 'en-us') {
            var decimals = '2';
            var decimal_sep = '.';
            var thousands_sep = ',';
        }
        var n = value.toString();
        n = eval('n.replace(/\\' + thousands_sep + '/g,"")');
        n = eval('n.replace(/\\' + decimal_sep + '/g,".")');
        return n;
    }
    return value;
}
function formatMoney(value) {
    var decimals = '2';
    var decimal_sep = ',';
    var thousands_sep = '.';
    if (window.navigator.systemLanguage == 'en-us') {
        var decimals = '2';
        var decimal_sep = '.';
        var thousands_sep = ',';
    }
    var n = value,
   c = isNaN(decimals) ? 2 : Math.abs(decimals), //if decimal is zero we must take it, it means user does not want to show any decimal
   d = decimal_sep || '.', //if no decimal separator is passed we use the dot as default decimal separator (we MUST use a decimal separator)

    /*
    according to [http://stackoverflow.com/questions/411352/how-best-to-determine-if-an-argument-is-not-sent-to-the-javascript-function]
    the fastest way to check for not defined parameter is to use typeof value === 'undefined' 
    rather than doing value === undefined.
    */
   t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, //if you don't want to use a thousands separator you can pass empty string as thousands_sep value

   sign = (n < 0) ? '-' : '',

    //extracting the absolute value of the integer part of the number and converting to string
   i = parseInt(n = Math.abs(n).toFixed(c)) + '',
   j = ((j = i.length) > 3) ? j % 3 : 0;
    return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}
function formatMoneyWhenChange(value) {
    var decimals = '2';
    var decimal_sep = ',';
    var thousands_sep = '.';
    if (window.navigator.systemLanguage == 'en-us') {
        var decimals = '2';
        var decimal_sep = '.';
        var thousands_sep = ',';
    }
    value = eval('value.replace(/\\' + thousands_sep + '/g,"")');
    var n = value.replace(thousands_sep, '').replace(decimal_sep, '.'),
   c = isNaN(decimals) ? 2 : Math.abs(decimals), //if decimal is zero we must take it, it means user does not want to show any decimal
   d = decimal_sep || '.', //if no decimal separator is passed we use the dot as default decimal separator (we MUST use a decimal separator)

    /*
    according to [http://stackoverflow.com/questions/411352/how-best-to-determine-if-an-argument-is-not-sent-to-the-javascript-function]
    the fastest way to check for not defined parameter is to use typeof value === 'undefined' 
    rather than doing value === undefined.
    */
   t = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep, //if you don't want to use a thousands separator you can pass empty string as thousands_sep value

   sign = (n < 0) ? '-' : '',

    //extracting the absolute value of the integer part of the number and converting to string
   i = parseInt(n = Math.abs(n).toFixed(c)) + '',
   j = ((j = i.length) > 3) ? j % 3 : 0;
    return sign + (j ? i.substr(0, j) + t : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
}
function NumberDisplayForCardPage(record) {
    for (var ix = 0; ix < record.fields.items.length; ix++) {
        var field = record.fields.items[ix];
        var value = record.get(field.name);
        if (value != null && value.toMoney != undefined) {
            if (Ext.getCmp(field.name) != null && Ext.getCmp(field.name) != undefined) {
                if (Ext.getCmp(field.name).xtype != 'combo')
                    Ext.getCmp(field.name).setValue(value.toMoney());

            }
        }
        switch (field.type.type) {
            case 'date':
                if (Ext.getCmp(field.name)) {
                    if (Ext.getCmp(field.name).xtype == 'displayfield') {
                        Ext.getCmp(field.name).setValue(Ext.util.Format.date(value));
                    }
                }
                break;
        }
    }
}


function saveData() {
    var values = grpAdvanceFilter.getStore().getRecordsValues();
    var filter = new Object();
    for (index = 0; index < values.length; index++) {
        if (values[index].FIELD != '' && values[index].VALUE != '')
            eval(String.format('filter.{0} = "{1}";', values[index].FIELD, values[index].VALUE));
    }
    Filter.setValue(Ext.encode(filter));
    //GridData.setValue(Ext.encode(grpList.getRowsValues({ selectedOnly: false })));
}


var lastScrollOffset = 20;
var statescroll = '';
var isCardChange = false;
var preventDefaultKey = function(e) {
    if (e.preventDefault) // non-IE browsers
        e.preventDefault();
    else  // IE Only
        e.returnValue = false;
    return false;
}
var doNewList = function(key, e) {
    if (e.ctrlKey) {
        OpenCard('new');
        preventDefaultKey(e);
    }
}
var CheckFormEdit = function() {
    return true;
    //var form = Ext.ComponentMgr.all.find(function(c) { return c.isXType && c.isXType('form'); });
    for (i = 0; i < Ext.ComponentMgr.all.items.length; i++) {
        if (Ext.ComponentMgr.all.items[i].isXType('form') || Ext.ComponentMgr.all.items[i].isXType('netgrid')) {
            if (Ext.ComponentMgr.all.items[i].isDirty()) {
                isCardChange = true;
                Ext.MessageBox.alert('Warning', 'Please save before do this action!');
                return true;
            }
        }

    }
}
var doEditList = function(key, e) {
    if (e.ctrlKey) {
        OpenCard('edit');
        preventDefaultKey(e);
    }
}
var doDeleteList = function(key, e) {
    if (e.ctrlKey) {
        OpenCard('delete');
        preventDefaultKey(e);
    }
}

var doSaveKM = function(key, e) {
    if (e.ctrlKey) {
        tbarSave.fireEvent('Click');
        preventDefaultKey(e);
    }
}

var doDeleteKM = function(key, e) {
    if (e.ctrlKey) {
        btnDeleteLines.fireEvent('Click');
        preventDefaultKey(e);
    }
    //    else {
    //        tbarDelete.fireEvent('Click');
    //    }

}

var doNewKM = function(key, e) {
    if (e.ctrlKey) {
        tbarNew.fireEvent('Click');
    }
    else {
        doNewLine();
    }
    preventDefaultKey(e);
}

function NewLine() {
    if (typeof (hdAfterSave.setValue('NEWLINE')) != 'undefined')
        NewLine();
}


var doEditKM = function(key, e) {
    if (e.ctrlKey) {
        tbarEdit.fireEvent('Click');
        preventDefaultKey(e);
    }

}

//var doCancelKM = function(key, e) {
//    tbarCancel.fireEvent('Click');
//}
function ShortcutKeyTrigger(el, e) {
    if (e.keyCode == e.F2) {
        switch (el.triggers.length) {
            case 1:
                el.fireEvent("triggerclick", el, el.triggers, 0, e);
                break;
            case 2:
                el.fireEvent("triggerclick", el, el.triggers, 1, e);
                break;
        }
        preventDefaultKey(e);
    }
}
function ShortcutKeyCombobox(el, e) {
    if (e.keyCode == e.F2) {
        switch (el.triggers.length) {
            case 2:
                el.fireEvent("triggerclick", el, el.triggers, 0, e);
                break;
            case 3:
                el.fireEvent("triggerclick", el, el.triggers, 2, e);
                break;
        }
        preventDefaultKey(e);
    }
}
var ctrlLookup = null;
var ctrlReturnValue = null;
var regTime = '^[0-9]{1,4}[HhDdMmYy]';

var checkToolbarMode = function(mode, checkStatus) {
    if (typeof (checkStatus) == 'undefined') {
        checkStatus = true;
    }
    if (typeof (mode) == 'undefined' || mode == null)
        mode = Ext.getCmp('hdfMode').getValue();

    switch (mode) {
        case 'new':
            Ext.onReady(function() {
                enableComtrolForEdit();
                if (Ext.getCmp('tbarNew'))
                    Ext.getCmp('tbarNew').disable();
                if (Ext.getCmp('tbarEdit'))
                    Ext.getCmp('tbarEdit').disable();
                if (Ext.getCmp('tbarDelete'))
                    Ext.getCmp('tbarDelete').disable();
                if (Ext.getCmp('tbarSave'))
                    Ext.getCmp('tbarSave').enable();
                if (Ext.getCmp('tbarCancel'))
                    Ext.getCmp('tbarCancel').enable();
                if (Ext.getCmp('tbarPrint'))
                    Ext.getCmp('tbarPrint').enable();
                if (Ext.getCmp('tbarPost'))
                    Ext.getCmp('tbarPost').enable();
                //            Ext.getCmp('tbarLast').disable();
                //            Ext.getCmp('tbarPrevious').disable();
                //            Ext.getCmp('tbarNext').disable();
                //            Ext.getCmp('tbarFirst').disable();
                if (typeof (LoadSpecialForEdit) != 'undefined') {
                    LoadSpecialForEdit();
                    return;
                }
                if (typeof (LoadSpecialForEditPPO) != 'undefined') {
                    LoadSpecialForEditPPO();
                    return;
                }
                if (typeof (LoadSpecialForEditSO) != 'undefined') {
                    LoadSpecialForEditSO();
                    return;
                }
                if (typeof (LoadSpecialForEditPresales) != 'undefined') {
                    LoadSpecialForEditPresales();
                    return;
                }
                if (typeof (LoadSpecialForEditDMSPhysJournal) != 'undefined') {
                    LoadSpecialForEditDMSPhysJournal();
                    return;
                }

                if (typeof (LoadSpecialValueForStockoutHeader) != 'undefined') {
                    LoadSpecialValueForStockoutHeader();
                    return;
                }
                if (typeof (LoadSpecialValueForRoutes) != 'undefined') {
                    LoadSpecialValueForRoutes();
                    return;
                }

                if (typeof (LoadSpecialValuePromotion) != 'undefined') {
                    LoadSpecialValuePromotion();
                    return;
                }
                if (typeof (LoadSpecialValueItem164) != 'undefined') {
                    LoadSpecialValueItem164();
                    return;
                }
                if (typeof (LoadSpecialValueReturnReason168) != 'undefined') {
                    LoadSpecialValueReturnReason168();
                    return;
                }
                if (typeof (LoadSpecialValueApplyFor114) != 'undefined') {
                    LoadSpecialValueApplyFor114();
                    return;
                }
                if (typeof (LoadSpecialValueLocation48) != 'undefined') {
                    LoadSpecialValueLocation48();
                    return;
                }
                if (typeof (LoadSpecialValueReturnBin203) != 'undefined') {
                    LoadSpecialValueReturnBin203();
                    return;
                }
                if (typeof (LoadSpecialValueSalesPriceHeader161) != 'undefined') {
                    LoadSpecialValueSalesPriceHeader161();
                    return;
                }
                if (typeof (LoadSpecialValueItemCustomGroupHeader58) != 'undefined') {
                    LoadSpecialValueItemCustomGroupHeader58();
                    return;
                }
                if (typeof (LoadSpecialValueHOBudgetHeaders158) != 'undefined') {
                    LoadSpecialValueHOBudgetHeaders158();
                    return;
                }
                if (typeof (LoadSpecialValueHOBudgetHeaders156) != 'undefined') {
                    LoadSpecialValueHOBudgetHeaders156();
                    return;
                }
                if (typeof (LoadSpecialValueReturnCustomerType291) != 'undefined') {
                    LoadSpecialValueReturnCustomerType291();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlaceMaster212) != 'undefined') {
                    LoadSpecialValueReturnVisitPlaceMaster212();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlaceType213) != 'undefined') {
                    LoadSpecialValueReturnVisitPlaceType213();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlanMasters211) != 'undefined') {
                    LoadSpecialValueReturnVisitPlanMasters211();
                    return;
                }
                if (typeof (LoadSpecialValueHOBudgetHeaders156) != 'undefined') {
                    LoadSpecialValueHOBudgetHeaders156();
                    return;
                }
                if (typeof (LoadSpecialValuePGMaster298) != 'undefined') {
                    LoadSpecialValuePGMaster298();
                    return;
                }
                if (typeof (LoadSpecialValueRoute277card) != 'undefined') {
                    LoadSpecialValueRoute277card();
                    return;
                }
                if (typeof (LoadSpecialValueRoute277card) != 'undefined') {
                    LoadSpecialValueRoute277card();
                    return;
                }
                if (typeof (LoadSpecialValueDMSSalesHeader290Card) != 'undefined') {
                    LoadSpecialValueDMSSalesHeader290Card();
                    return;
                } 
            });
            break;
        case 'edit':

            Ext.onReady(function() {
                if (typeof (Status) != 'undefined') {
                    //if (Status.getValue() == 'Released') {
                    //                    if (Status.getValue() == 1) {
                    //                        if (typeof (LoadSpecialForEdit) != 'undefined') {
                    //                            LoadSpecialForEdit();
                    //                        }
                    //                        //hdfMode.setValue('view');
                    //                        return;
                    //                    }
                }
                enableComtrolForEdit();
                //Ext.getCmp('tbarEdit').fireEvent('Click');
                if (Ext.getCmp('tbarNew'))
                    Ext.getCmp('tbarNew').enable();
                if (Ext.getCmp('tbarEdit'))
                    Ext.getCmp('tbarEdit').disable();
                if (Ext.getCmp('tbarDelete'))
                    Ext.getCmp('tbarDelete').disable();
                if (Ext.getCmp('tbarSave'))
                    Ext.getCmp('tbarSave').enable();
                if (Ext.getCmp('tbarCancel'))
                    Ext.getCmp('tbarCancel').enable();
                if (Ext.getCmp('tbarPrint'))
                    Ext.getCmp('tbarPrint').enable();
                if (Ext.getCmp('tbarPost'))
                    Ext.getCmp('tbarPost').enable();
                //                if (Ext.getCmp('grdLines'))
                //                    Ext.getCmp('grdLines').enable();
                //            Ext.getCmp('tbarLast').disable();
                //            Ext.getCmp('tbarPrevious').disable();
                //            Ext.getCmp('tbarNext').disable();
                //            Ext.getCmp('tbarFirst').disable();
                if (typeof (Ext.getCmp('Status')) != 'undefined' && checkStatus == true) {
                    //var status = Ext.getCmp('Status').getValue();
                    //var status = stoCard.data.items[0].data.Status;
                    //if (status == 'Released') {
                    //                    if (status == 1) {
                    //                        disableComtrolForView();
                    //                    }                    
                }
                if (typeof (LoadSpecialForEdit) != 'undefined') {
                    LoadSpecialForEdit();
                    return;
                }
                if (typeof (LoadSpecialForEditPPO) != 'undefined') {
                    LoadSpecialForEditPPO();
                    return;
                }
                if (typeof (LoadSpecialForEditSO) != 'undefined') {
                    LoadSpecialForEditSO();
                    return;
                }
                if (typeof (LoadSpecialForEditPresales) != 'undefined') {
                    LoadSpecialForEditPresales();
                    return;
                }
                if (typeof (LoadSpecialForEditDMSPhysJournal) != 'undefined') {
                    LoadSpecialForEditDMSPhysJournal();
                    return;
                }

                if (typeof (LoadSpecialValueForStockoutHeader) != 'undefined') {
                    LoadSpecialValueForStockoutHeader();
                    return;
                }
                if (typeof (LoadSpecialValueForRoutes) != 'undefined') {
                    LoadSpecialValueForRoutes();
                    return;
                }
                

                if (typeof (LoadSpecialValuePromotion) != 'undefined') {
                    LoadSpecialValuePromotion();
                    return;
                }
                if (typeof (LoadSpecialValueItem164) != 'undefined') {
                    LoadSpecialValueItem164();
                    return;
                }
                if (typeof (LoadSpecialValueReturnReason168) != 'undefined') {
                    LoadSpecialValueReturnReason168();
                    return;
                }
                if (typeof (LoadSpecialValueApplyFor114) != 'undefined') {
                    LoadSpecialValueApplyFor114();
                    return;
                }
                if (typeof (LoadSpecialValueLocation48) != 'undefined') {
                    LoadSpecialValueLocation48();
                    return;
                }
                if (typeof (LoadSpecialValueReturnBin203) != 'undefined') {
                    LoadSpecialValueReturnBin203();
                    return;
                }
                if (typeof (LoadSpecialValueSalesPriceHeader161) != 'undefined') {
                    LoadSpecialValueSalesPriceHeader161();
                    return;
                }
                if (typeof (LoadSpecialValueItemCustomGroupHeader58) != 'undefined') {
                    LoadSpecialValueItemCustomGroupHeader58();
                    return;
                }
                if (typeof (LoadSpecialValueHOBudgetHeaders158) != 'undefined') {
                    LoadSpecialValueHOBudgetHeaders158();
                    return;
                }
                if (typeof (LoadSpecialValueReturnCustomerType291) != 'undefined') {
                    LoadSpecialValueReturnCustomerType291();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlaceMaster212) != 'undefined') {
                    LoadSpecialValueReturnVisitPlaceMaster212();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlaceType213) != 'undefined') {
                    LoadSpecialValueReturnVisitPlaceType213();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlanMasters211) != 'undefined') {
                    LoadSpecialValueReturnVisitPlanMasters211();
                    return;
                }
                if (typeof (LoadSpecialValueHOBudgetHeaders156) != 'undefined') {
                    LoadSpecialValueHOBudgetHeaders156();
                    return;
                }
                if (typeof (LoadSpecialValuePGMaster298) != 'undefined') {
                    LoadSpecialValuePGMaster298();
                    return;
                }
                if (typeof (LoadSpecialValueRoute277card) != 'undefined') {
                    LoadSpecialValueRoute277card();
                    return;
                }
                if (typeof (LoadSpecialValueDMSSalesHeader290Card) != 'undefined') {
                    LoadSpecialValueDMSSalesHeader290Card();
                    return;
                } 
            });
            break;
        case 'view':
            Ext.onReady(function() {
                //disableComtrolForView();
                ReadOnlyComtrolForView();
                if (Ext.getCmp('tbarNew'))
                    Ext.getCmp('tbarNew').enable();
                if (Ext.getCmp('tbarEdit'))
                    Ext.getCmp('tbarEdit').enable();
                if (Ext.getCmp('tbarDelete')) {
                    Ext.getCmp('tbarDelete').enable();
                }
                if (Ext.getCmp('tbarSave'))
                    Ext.getCmp('tbarSave').disable();
                if (Ext.getCmp('tbarCancel'))
                    Ext.getCmp('tbarCancel').disable();
                if (Ext.getCmp('tbarPrint'))
                    Ext.getCmp('tbarPrint').enable();
                if (Ext.getCmp('tbarPost'))
                    Ext.getCmp('tbarPost').enable();
                //                if (Ext.getCmp('grdLines'))
                //                    Ext.getCmp('grdLines').disable();
                //            Ext.getCmp('tbarLast').enable();
                //            Ext.getCmp('tbarPrevious').enable();
                //            if(Ext.getCmp('tbarNext'))
                //                Ext.getCmp('tbarNext').enable();
                //            Ext.getCmp('tbarFirst').enable();
                //                if (Ext.getCmp('Status') && checkStatus == true) {
                //                    var status = Ext.getCmp('Status').getValue();
                //                    if (status == 'Released') {
                //                        if (Ext.getCmp('tbarEdit'))
                //                            Ext.getCmp('tbarEdit').disable();
                //                        if (Ext.getCmp('tbarDelete'))
                //                            Ext.getCmp('tbarDelete').disable();
                //                        if (Ext.getCmp('tbarSave'))
                //                            Ext.getCmp('tbarSave').disable();
                //                    }
                //                }
                if (typeof (LoadSpecialForEditSO) != 'undefined') {
                    LoadSpecialForEditSO();
                    return;
                }

                if (typeof (LoadSpecialValueForStockoutHeader) != 'undefined') {
                    LoadSpecialValueForStockoutHeader();
                    return;
                }
                if (typeof (LoadSpecialValueForRoutes) != 'undefined') {
                    LoadSpecialValueForRoutes();
                    return;
                }

                if (typeof (LoadSpecialValuePromotion) != 'undefined') {
                    LoadSpecialValuePromotion();
                    return;
                }
                if (typeof (LoadSpecialValueItem164) != 'undefined') {
                    LoadSpecialValueItem164();
                    return;
                }
                if (typeof (LoadSpecialValueReturnReason168) != 'undefined') {
                    LoadSpecialValueReturnReason168();
                    return;
                }
                if (typeof (LoadSpecialValueApplyFor114) != 'undefined') {
                    LoadSpecialValueApplyFor114();
                    return;
                }
                if (typeof (LoadSpecialValueLocation48) != 'undefined') {
                    LoadSpecialValueLocation48();
                    return;
                }
                if (typeof (LoadSpecialValueReturnBin203) != 'undefined') {
                    LoadSpecialValueReturnBin203();
                    return;
                }
                if (typeof (LoadSpecialValueSalesPriceHeader161) != 'undefined') {
                    LoadSpecialValueSalesPriceHeader161();
                    return;
                }
                if (typeof (LoadSpecialValueItemCustomGroupHeader58) != 'undefined') {
                    LoadSpecialValueItemCustomGroupHeader58();
                    return;
                }
                if (typeof (LoadSpecialValueHOBudgetHeaders158) != 'undefined') {
                    LoadSpecialValueHOBudgetHeaders158();
                    return;
                }
                if (typeof (LoadSpecialValueHOBudgetHeaders156) != 'undefined') {
                    LoadSpecialValueHOBudgetHeaders156();
                    return;
                }
                if (typeof (LoadSpecialValueReturnCustomerType291) != 'undefined') {
                    LoadSpecialValueReturnCustomerType291();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlaceMaster212) != 'undefined') {
                    LoadSpecialValueReturnVisitPlaceMaster212();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlaceType213) != 'undefined') {
                    LoadSpecialValueReturnVisitPlaceType213();
                    return;
                }
                if (typeof (LoadSpecialValueReturnVisitPlanMasters211) != 'undefined') {
                    LoadSpecialValueReturnVisitPlanMasters211();
                    return;
                }
                if (typeof (LoadSpecialValuePGMaster298) != 'undefined') {
                    LoadSpecialValuePGMaster298();
                    return;
                }
                if (typeof (LoadSpecialValueRoute277card) != 'undefined') {
                    LoadSpecialValueRoute277card();
                    return;
                }
                if (typeof (LoadSpecialValueDMSSalesHeader290Card) != 'undefined') {
                    LoadSpecialValueDMSSalesHeader290Card();
                    return;
                } 
            });
            break;
        case 'approve':
            Ext.onReady(function() {
                //disableComtrolForView();
                ReadOnlyComtrolForView();
                if (Ext.getCmp('tbarNew'))
                    Ext.getCmp('tbarNew').enable();
                if (Ext.getCmp('tbarEdit'))
                    Ext.getCmp('tbarEdit').enable();
                if (Ext.getCmp('tbarDelete')) {
                    Ext.getCmp('tbarDelete').enable();
                }
                if (Ext.getCmp('tbarSave'))
                    Ext.getCmp('tbarSave').disable();
                if (Ext.getCmp('tbarCancel'))
                    Ext.getCmp('tbarCancel').disable();
                if (Ext.getCmp('tbarPrint'))
                    Ext.getCmp('tbarPrint').enable();
                if (Ext.getCmp('tbarPost'))
                    Ext.getCmp('tbarPost').enable();
                //                if (Ext.getCmp('grdLines'))
                //                    Ext.getCmp('grdLines').disable();
                //            Ext.getCmp('tbarLast').enable();
                //            Ext.getCmp('tbarPrevious').enable();
                //            if(Ext.getCmp('tbarNext'))
                //                Ext.getCmp('tbarNext').enable();
                //            Ext.getCmp('tbarFirst').enable();
                if (Ext.getCmp('Status') && checkStatus == true) {
                    var status = Ext.getCmp('Status').getValue();
                    //if (status == 'Released') {
                    if (status == 1) {
                        if (Ext.getCmp('tbarEdit'))
                            Ext.getCmp('tbarEdit').disable();
                        if (Ext.getCmp('tbarDelete'))
                            Ext.getCmp('tbarDelete').disable();
                        if (Ext.getCmp('tbarSave'))
                            Ext.getCmp('tbarSave').disable();
                    }
                }
                //                if (typeof (LoadSpecialForEdit) != 'undefined') {
                //                    LoadSpecialForEdit();
                //                    return;
                //                }
            });
            break;
        case 'delete':
            Ext.onReady(function() {
                //disableComtrolForView();
                ReadOnlyComtrolForView();
                if (Ext.getCmp('tbarNew'))
                    Ext.getCmp('tbarNew').enable();
                if (Ext.getCmp('tbarEdit'))
                    Ext.getCmp('tbarEdit').enable();
                if (Ext.getCmp('tbarDelete')) {
                    Ext.getCmp('tbarDelete').enable();
                    Ext.getCmp('tbarDelete').fireEvent('Click');
                }
                if (Ext.getCmp('tbarSave'))
                    Ext.getCmp('tbarSave').disable();
                if (Ext.getCmp('tbarCancel'))
                    Ext.getCmp('tbarCancel').disable();
                if (Ext.getCmp('tbarPrint'))
                    Ext.getCmp('tbarPrint').enable();
                if (Ext.getCmp('tbarPost'))
                    Ext.getCmp('tbarPost').enable();
                //                if (Ext.getCmp('grdLines'))
                //                    Ext.getCmp('grdLines').disable();    
                //            Ext.getCmp('tbarLast').enable();
                //            Ext.getCmp('tbarPrevious').enable();
                //            if(Ext.getCmp('tbarNext'))
                //                Ext.getCmp('tbarNext').enable();
                //            Ext.getCmp('tbarFirst').enable();
            });
            break;
        default:
            Ext.onReady(function() {
                disableComtrolForView();
                if (Ext.getCmp('tbarNew'))
                    Ext.getCmp('tbarNew').enable();
                if (Ext.getCmp('tbarEdit'))
                    Ext.getCmp('tbarEdit').disable();
                if (Ext.getCmp('tbarDelete'))
                    Ext.getCmp('tbarDelete').disable();
                if (Ext.getCmp('tbarSave'))
                    Ext.getCmp('tbarSave').enable();
                if (Ext.getCmp('tbarCancel'))
                    Ext.getCmp('tbarCancel').disable();
                if (Ext.getCmp('tbarPrint'))
                    Ext.getCmp('tbarPrint').disable();
                if (Ext.getCmp('tbarPost'))
                    Ext.getCmp('tbarPost').disable();
                //            Ext.getCmp('tbarLast').disable();
                //            Ext.getCmp('tbarPrevious').disable();
                //            Ext.getCmp('tbarNext').disable();
                //            Ext.getCmp('tbarFirst').disable();
            });
            break;
    }

}

var checkToolbarModeCard4 = function(mode, checkStatus) {
    if (typeof (checkStatus) == 'undefined') {
        checkStatus = true;
    }
    if (typeof (mode) == 'undefined' || mode == null)
        mode = Ext.getCmp('hdfMode').getValue();

    switch (mode) {
        case 'view':
            ReadOnlyComtrolForView();
    }

}

var filterString = function(value, dataIndex, record) {
    var val = record.get(dataIndex);
    if (typeof val != "string") {
        return value.length == 0;
    }
    return val.toLowerCase().indexOf(value.toLowerCase()) > -1;
}

var filterDate = function(value, dataIndex, record) {
    if (value == null || record.get(dataIndex) == null)
        return true;
    var val = record.get(dataIndex).clearTime(true).getTime();

    if (!Ext.isEmpty(value, false) && val != value.clearTime(true).getTime()) {
        return false;
    }
    return true;
}

var filterNumber = function(value, dataIndex, record) {
    var val = record.get(dataIndex);

    if (!Ext.isEmpty(value, false) && val != value) {
        return false;
    }
    return true;
}
var disableComtrolForView = function() {

    var forms = Ext.ComponentMgr.all.filter('xtype', 'form');
    for (i = 0; i < forms.items.length; i++) {
        for (j = 0; j < forms.items[i].form.items.length; j++)
        //forms.items[i].form.items.items[j].setReadOnly(true);
            forms.items[i].form.items.items[j].disable();

    }
    var grids = Ext.ComponentMgr.all.filter('xtype', 'coolitegrid');
    for (i = 0; i < grids.items.length; i++) {
        grids.items[i].stopEditing(true);
    }
}

var ReadOnlyComtrolForView = function() {
    var forms = Ext.ComponentMgr.all.filter('xtype', 'form');
    for (i = 0; i < forms.items.length; i++) {
        for (j = 0; j < forms.items[i].form.items.length; j++) {
            forms.items[i].form.items.items[j].setReadOnly(true);
            forms.items[i].form.items.items[j].readOnly = true;
            if (forms.items[i].form.items.items[j].xtype == 'checkbox') {
                forms.items[i].form.items.items[j].disable();
                //forms.items[i].form.items.items[j].disable = true;               
            }
        }
    }
    var grids = Ext.ComponentMgr.all.filter('xtype', 'netgrid');
    for (i = 0; i < grids.items.length; i++) {
        grids.items[i].stopEditing(true);        
    }
}


var enableComtrolForEdit = function(hasReset) {
    var forms = Ext.ComponentMgr.all.filter('xtype', 'form');
    for (i = 0; i < forms.items.length; i++) {
        for (j = 0; j < forms.items[i].form.items.length; j++) {
            forms.items[i].form.items.items[j].setReadOnly(false);
            //if (!forms.items[i].form.items.items[j].readOnly)
            //forms.items[i].form.items.items[j].enable();
            if (forms.items[i].form.items.items[j].xtype == 'checkbox') {
                forms.items[i].form.items.items[j].enable();
                //forms.items[i].form.items.items[j].disable = true;               
            }
        }
        if (hasReset)
            forms.items[i].reset();
    }
    var grids = Ext.ComponentMgr.all.filter('xtype', 'coolitegrid');
    for (i = 0; i < grids.items.length; i++) {
        grids.items[i].enable();
        if (hasReset)
            grids.items[i].clear();
    }
}
var PreventNegativeDisplay = function(value) {
    if (value <= 0) return ''; return value;
}
var PreventBlankDisplay = function(value) {
    if (Ext.isEmpty(value) || value == '_blank_') return ''; return value.replace('_', ' ');
}
var MultiComboRenderer = function(value, option) {
    if (Ext.isEmpty(value) || value == '_blank_') return '';
    var returnValue = '';
    var optionStrings = option.split(',');
    var values = value.split(',');
    for (var i = 0; i < values.length - 1; i++) {
        returnValue += optionStrings[values[i]] + ','
    }
    returnValue += optionStrings[values[values.length - 1]];
    return returnValue;
}
var ComboRenderer = function(value, option) {

    if (Ext.isEmpty(value) || value == '_blank_') return '';
    var optionStrings = option.split(',');
    return optionStrings[value];
}

var PreventMinDateDisplay = function(value) {
    //if (value <= '1753 - 01 - 01' || value.toString().match('*1753*') || value <= '1753/1/1') return ''; return value;
    var val = value.clearTime(true).getTime();
    var mindate = Date.parse('1753/1/1');
    if (val == mindate.clearTime(true).getTime()) {
        return '';
    }
    return value;

}
var LinkRender = function(value) {
    return '<a href="/' + value + '">' + value + '</a>';
}
var InsertBlankRowToStore = function(store, count) {
    if (isNaN(count)) {
        count = 5;
    }
    for (i = 0; i < count; i++) {
        store.addRecord();
    }
    store.commitChanges();
}

var CanEditGrid = function(e, mode) {
    if (typeof (mode) == 'undefined') {
        mode = hdfMode.getValue();
    }
    if (mode == 'view') {
        e.cancel = true;
    }

}
//DungNC
var CanEditGridforCol = function(e, mode) {
    if (typeof (mode) == 'undefined') {
        mode = hdfMode.getValue();
    }
    if (mode == 'view') {
        e.cancel = true;
    }
    if (tableName == "DMS Phys Journal") {
        var ads = grdLines;
        ads.colModel.columns[1].editable = false;
        ads.getColumnModel().isCellEditable = function(col, row) {
            var record = ads.store.getAt(row);
            if (col == '1') { // replace with your condition
                return false;
            }
            return Ext.grid.ColumnModel.prototype.isCellEditable.call(this, col, row);
        }
    }
}

function SetAfterSave(value) {
    hdAfterSave.setValue(value);
    if (typeof (btnSaveBG) != 'undefined') {
        btnSaveBG.fireEvent('click');
    }
    else {
        tbarSave.fireEvent('click');
    }
    return false;
}

function DeleteNullLines(grd, field) {
    if (field == null || field == '') {
        field = 'Item_No';
    }
    var selItems = grd.store.data.clone().items;
    var count = selItems.length;
    for (i = 0; i < count; i++) {
        if (selItems[i].get(field) == null || selItems[i].get(field) == '') {
            grd.store.remove(selItems[i]);
        }
    }
}
function DeleteLines(el, type, action, extraParams, grd, Key) {
    if (Ext.getCmp('Status')) {
        var status = Ext.getCmp('Status').getValue();
        if (status == '1') {
            return false;
        }
    }
    if (Ext.getCmp('hdfMode')) {
        if (hdfMode.getValue() == 'view')
            return false;
    }
    if (Key == null || Key == '') {
        Key = 'Key';
    }
    var postserver = false;
    grd.stopEditing(true);


    //    for (var il = 0; il < grd.store.data.items.length; il++) {
    //        if (grd.store.data.items[il].data.Selected == true) {
    //            delrecords.push(grd.store.data.items[il]);
    //        }
    //    }

    grd.deleteSelected();
    var delrecords = grd.store.getDeletedRecords();
    for (i = 0; i < delrecords.length; i++) {
        if (delrecords[i].get(Key) == '') {
            grd.store.remove(delrecords[i]);
        }
        else {
            postserver = true;
        }
    }
    if (postserver) {
        var deleteItems = grd.store.getDeletedRecords();
        var deletekeys = "";
        for (var i = 0; i < deleteItems.length; i++) {
            if (deleteItems[i].data.Key != null && deleteItems[i].data.Key != '') {
                deletekeys += deleteItems[i].data.Key + '|';
            }
        }
        if (typeof (extraParams) != 'undefined' && extraParams != null) {
            extraParams.DELETEDLINES = deletekeys;
        } else if (typeof (hdfDeleteLineKey) != 'undefined') {
            hdfDeleteLineKey.setValue(deletekeys);
        }

    }
    if (!grd.getSelectionModel().hasSelection()) {
        if (typeof (btnDeleteLines) != 'undefined') {
            btnDeleteLines.disable();
        }
    }
    return postserver;
}
function DefaultGridBeforeSave(grd, all) {
    if (typeof (CheckforItemUnitOfMeasure) != 'undefined') {
        CheckforItemUnitOfMeasure();
    }
    //check for Applyfor
    if (typeof (CheckforApplyFor) != 'undefined') {
        CheckforApplyFor();
    }
    if (typeof (CheckforBinList) != 'undefined') {
        return CheckforBinList();
    }    
    for (i = 0; i < grd.store.data.length; i++) {
        if (grd.store.data.items[i].dirty | all) {
            if (!DefaultFieldBeforeSave(grd.store.data.items[i], grd))
                return false;
        }
    }
    return true;
}
function DefaultFieldBeforeSave(record, grd) {
    //tableName = record.store.reader.meta.idProperty;
    if (typeof (record) == 'undefined')
        return;
    if (record.get('Key') != 'undefined' && record.get('Key') == "") {
        record.set('Key', null)
    }
    var iValidmsg = TXTisvalidfield;
    var fieldCaption = '';
    for (var ft = 0; ft < record.fields.length; ft++) {

        var name = record.fields.items[ft].name;
        if (typeof (grd) != 'undefined') {
            //var column = grd.colModel.lookup[tableName.replace(' ', '_') + '_' + name]; dailt
            var column = grd.colModel.columns[ft];
            if (typeof (column) != 'undefined')
                fieldCaption = column.header;
        }
        else {
            var control = Ext.getCmp(name);
            if (typeof (control) != 'undefined') {
                fieldCaption = control.fieldLabel;
            }
        }
        if (Ext.isEmpty(record.get(name)) | record.get(name) == null) {
            if (!record.fields.items[ft].allowBlank) {
                if (grd != null) {

                }
                Ext.Msg.alert(TXTMessage, String.format(iValidmsg, fieldCaption)); return false;
            }
        }
        switch (record.fields.items[ft].type.type) {
            case 'date': 
                if (record.get(name) == '' || record.get(name) == null) {
                    if (!record.fields.items[ft].allowBlank) {
                        if (grd != null) {

                        }
                        Ext.Msg.alert(TXTMessage, String.format(iValidmsg, fieldCaption));

                        return false;
                    }
                    record.set(name, '0001-1-1');
                }
                else if (typeof (record.get(name)) == 'string' && record.get(name) != '0001-1-1')
                    record.set(name, Ext.util.Format.date(record.get(name), dateStandartFormat));
                break;
            case 'float':
                if (record.get(name) == null || record.get(name) == '') {
                    record.set(name, 0);
                }
                else
                    record.set(name, removeThousandsSeparator(record.get(name)))
                if (isNaN(record.get(name)))
                    record.set(name, 0);
                break;
            case 'int':
                if (record.get(name) == '' || record.get(name) == null) {
                    record.set(name, 0);
                }
                else
                //record.set(name, removeThousandsSeparator(record.get(name)))
                    record.set(name, parseInt(removeThousandsSeparator(record.get(name))));

                if (isNaN(record.get(name)))
                    record.set(name, 0);
                break;
            case 'boolean':
            case 'bool':
                if (record.get(name) == null) {
                    record.set(name, 0);
                }
                if (isNaN(record.get(name)))
                    record.set(name, 0);
                break;
        }
    }
    //if (!record.isValid())
    //    return false;
    return true;
}
function SetDefaultDataEditGrid(e) {
    switch (e.record.fields.get(e.field).type.type) {
        case 'float':
        case 'int':
            if (Ext.isEmpty(e.record.get(e.field)))
                e.record.set(e.field, 0);
            break;
    }
}
function NotRoundingNumberField(el, newValue, oldValue) {
    if (newValue) {
        var tp = (1 / (el.decimalPrecision + 1) * 10) * 5;
        el.setValue(newValue - newValue);
    }
}
function FormatNumber(value, Precision) {
    if (isNaN(value)) {
        return value;
    }
    if (Precision)
        Precision = 2;
    switch (Precision) {
        case 0:
            return Ext.util.Format.number(value, '0.000/i');
            break;
        case 5:
            return Ext.util.Format.number(value, '0.000,00000/i');
            break;
        default:
            return Ext.util.Format.number(value, '0.000,00/i');
            break;
    }
}
function CheckMandatoryStore(grid, fields) {
    var afields = fields.split(',');
    for (i = 0; i < grid.store.data.items.length; i++) {
        var record = grid.store.data.items[i];
        for (j = 0; j < afields.length; j++) {
            if (Ext.isEmpty(record.get(afields[j]))) {
                return false;
            }
        }
    }
    return true;
}
function GridListAfterRender(grd) {
    var page = Cookies.get(window.location.pathname + grd.id);
    if (page != null && grd.getPagingToolbar() != null) {
        grd.getPagingToolbar().changePage(page);
        var id = Cookies.get(window.location.pathname + grd.id + 'id');
        //grd.getSelectionModel().selectById(id);
        //grd.getSelectionModel().selectRow(0);
        //grd.getView().focusRow(0);
    }
}
function SetPagingHistory(grd) {
    if (grd.getPagingToolbar() != null) {
        Cookies.set(window.location.pathname + grd.id, grd.getPagingToolbar().getPageData().activePage);
        if (grd.hasSelection()) {
            Cookies.set(window.location.pathname + grd.id + 'id', grd.getSelectionModel().getSelections()[0].id);
        }
    }
}
function DocumentReadyList() {
    var windowParent = parent.Ext.getCmp(this.name.replace('_IFrame', ''));
    if ((typeof (windowParent) != 'undefined' && windowParent.getXType() == 'window') || typeof (window.parent.load) == 'undefined' || window.parent.location == window.location) {
        if (typeof (tbarReload) != 'undefined') {
            tbarReload.disable();
            tbarReload.hide();
        }
        if (typeof (tbarClose) != 'undefined') {
            tbarClose.hide();
            tbarClose.disable();
        }
    }
    //test();
}
function WindowUnloadList() {
    if (typeof (grpList) != 'undefined')
        SetPagingHistory(grpList);
}
function DocumentReadyCard() {
    if (typeof (No) != 'undefined' && No != null && typeof (No.focus) != 'undefined') {
        (function() { No.focus(); }).defer(300);
    }
    var windowParent = parent.Ext.getCmp(this.name.replace('_IFrame', ''));
    if ((typeof (windowParent) != 'undefined' && windowParent.getXType() == 'window') || typeof (window.parent.load) == 'undefined' || window.parent.location == window.location) {
        if (typeof (tbarReload) != 'undefined') {
            tbarReload.disable();
            tbarReload.hide();
        }
        if (typeof (tbarClose) != 'undefined') {
            tbarClose.hide();
            tbarClose.disable();
        }
    }
    if (Ext) {
        Ext.form.NumberField.prototype.fixPrecision = function(value) {
            var nan = isNaN(value);
            if (!this.allowDecimals || this.decimalPrecision == -1 || nan || !value) {
                return nan ? '' : value;
            }
            var paths = value.toString().split(this.decimalSeparator);
            if (paths.length == 2) {
                var cusprecision = Ext.util.Format.substr(paths[1], 0, this.decimalPrecision);
                value = paths[0] + this.decimalSeparator + cusprecision;
                return value;
            }
            return value;
            var rex = 0;
            //            if (Ext.isIE)
            //                rex = 5 / Math.pow(10, (this.decimalPrecision + 1));
            //            else
            //                rex = 4 / Math.pow(10, (this.decimalPrecision + 1));
            //return parseFloat((parseFloat(value) - rex).toFixed(this.decimalPrecision));
        };
        Ext.form.NumberField.prototype.decimalSeparator = ",";
        Ext.form.NumberField.prototype.decimalPrecision = "5";
    }

}
function WindowUnloadCard() {
}
function OpenWin2(url) {
    window.location = url;
}
function OpenWin3(url) {
    window.open(url, 'pop_win', 'toolbar=1,status=0,resizable=1,scrollbars=1,maximize=1');
}
function OpenWin(url, width, height) {
    if (typeof (width) == 'undefined') {
        width = 800;
    }
    if (typeof (height) == 'undefined') {
        width = 600;
    }
    var newWindow = window.open(url, 'pop_win', 'width=' + width + ',height=' + height + ',toolbar=1,status=0,resizable=1,scrollbars=1');
    newWindow.creator = self;
    //newWindow.parent = self;
    newWindow.opener = self;
    //window.open(url, 'pop_win', 'width=' + width + ',height=' + height + ',toolbar=1,status=0,resizable=1,scrollbars=1,fullscreen=1,directories=0');
}
function load(url, idRecord) {
    if (url.charAt(0) != '/')
        url = '/' + url;
    var windowParent = parent.Ext.getCmp(this.name.replace('_IFrame', ''));
    if ((typeof (windowParent) != 'undefined' && windowParent.getXType() == 'window')) {
        windowParent.load(url);
        //window.location = url;
    }
    else if (typeof (window.parent.load) != 'undefined' && window.parent.location != window.location) {
        window.parent.load(url, windowParent.title + "-" + idRecord, windowParent.id + "_" + idRecord);
    }
    else {

        OpenWin2(url);
    }
}
function loadforList3(url, idRecord, title) {
    if (url.charAt(0) != '/')
        url = '/' + url;
    var windowParent = parent.Ext.getCmp(this.name.replace('_IFrame', ''));
    if ((typeof (windowParent) != 'undefined' && windowParent.getXType() == 'window')) {
        windowParent.load(url);
        //window.location = url;
    }
    else if (typeof (window.parent.load) != 'undefined' && window.parent.location != window.location) {
        window.parent.load(url, title + "-" + idRecord, windowParent.id + "_" + idRecord);
    }
    else {

        OpenWin2(url);
    }
}
function closeTabNode() {
    window.parent.removeTab();
    var windowParent = window.parent.Ext.getCmp(this.name.split('_')[0]);
    windowParent.load(window.parent.Ext.getCmp(this.name.split('_')[0]).autoLoad.url);
}
function reloadFrameNode(id) {
    var windowParent = window.parent.Ext.getCmp(id);
    windowParent.load(windowParent.autoLoad.url);
}
function reload() {
    var windowParent = window.parent.Ext.getCmp(this.name.replace('_IFrame', ''));
    var iframmain = document.getElementById(panelMain.iframe.id);
    var hdfmode = iframmain.contentWindow.Ext.getCmp('hdfMode');
    var No = iframmain.contentWindow.Ext.getCmp('No');
    var mode = 'view';
    if (typeof (hdfmode) != 'undefined') {
        mode = hdfmode.getValue();
    }
    if (mode == 'new') {
        mode = 'edit';
    }

    if (panelMain.autoLoad.url) {
        var url = iframmain.contentWindow.location.href;
        url = url.replace('mode=new', 'mode=' + mode);
        url = url.replace('mode=view', 'mode=' + mode);
        if (No) {
            //url = url.toLowerCase().replace('no=', 'old=');
            //url = url + '&no=' + No.getValue();
        }
        panelMain.load(url);
    }

}
var showReport = function(url, title) {
    if (parent.wndReportViewer) {
        if (typeof (url) == 'undefined') {
            parent.wndReportViewer.clearContent();
        }
        else {
            parent.wndReportViewer.setTitle(title);
            //wndReportViewer.title = title;
            parent.wndReportViewer.load(url);
            parent.wndReportViewer.center();
            parent.wndReportViewer.show();
        }
    }
    else {
        window.document.title = title;
        window.location = url;
    }
}
var Cookies = {};
Cookies.set = function(name, value) {
    var argv = arguments;
    var argc = arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : '/';
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
       ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
       ((path == null) ? "" : ("; path=" + path)) +
       ((domain == null) ? "" : ("; domain=" + domain)) +
       ((secure == true) ? "; secure" : "");
};

Cookies.get = function(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    var j = 0;
    while (i < clen) {
        j = i + alen;
        if (document.cookie.substring(i, j) == arg)
            return Cookies.getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0)
            break;
    }
    return null;
};

Cookies.clear = function(name) {
    if (Cookies.get(name)) {
        document.cookie = name + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
};

Cookies.getCookieVal = function(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
};
function GetItemLookupForItem(item, trigger, index, e) {

    var record = null;
    var type = stoCard.data.items[0].data.No;

    var url = '';

    var wnd = Ext.getCmp('wndLookUp');

    ctrlLookup = item;
    wnd.setTitle('');
    url = '/Lookup.aspx?met=223&filter=Item_No:' + type;
    if (wnd.autoLoad.url == url) {
        wnd.show(); return;
    }
    wnd.load(url);
    wnd.center();
    wnd.setTitle(TXTFind + item.fieldLabel.toLowerCase());
    wnd.show();
    // }

}
function SetOnReady() {
    Date.dayNames = ["Chủ nhật", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy"];
    Date.monthNames = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
    if (Ext.form.DateField) {
        Ext.apply(Ext.form.DateField.prototype, {
            dayNames: ["Chủ nhật", "Hai", "Ba", "Tư", "Năm", "Sáu", "Bảy"],
            altFormats: "d/m/Y|d-m-y|d-m-Y|d/m|d-m|dm|dmy|dmY|d|Y-m-d"
        });
    }
    if (Ext.DatePicker) {
        Ext.apply(Ext.DatePicker.prototype, {
            okText: 'Đồng ý',
            cancelText: 'Hủy'

        });
    }
}

var buybackPurity_Percentalert = 'Giá trị phải nhỏ hơn hoặc bằng 100. Giá trị nhập=';
var itemNoExist = 'Mã hàng này không tồn tại. Bạn có muốn xóa dòng này';

var InquiryDateAlert = '"Ngày" cần đươc nhập';
var RequireNotBlank = 'Những trường cần thiết không được bỏ trống!';
var SalesOrderStatusOpenAlert = '"Tình trạng" phải có giá trị là "Open".';
var NoIsNotBlank = '"Mã" cần phải nhập!';
var BomItemNoIsNotBlank = '"Mã hàng BOM" cần phải nhập!';
var QuantityIsNotBlank = '"Số lượng" cần phải nhập!';
var DepotIsNotBlank = '"Mã kho" cần phải nhập!';
var DocNotIsNotBlank = '"Mã chứng từ" cần phải nhập!';
var SalesTeamIsNotBlank = '"Mã đội bán hàng" cần phải nhập!';
var HaveLineNotDo = 'Đã tồn tại dòng chi tiết, cần xóa chi tiết trước khi chạy chức năng này!';
var QuantityShipped0 = 'Số lượng đã chuyển cần = 0.';
var FreeItemTypeEmpty = '"Loại hàng khuyến mãi" phải là "" ';
var WarehouseShipmentCreated = 'Phiếu chuyển kho đã được tạo';
var WarehouseReceiptCreated = 'Phiếu nhập kho đã được tạo';
var PostedAlert = "Chứng từ đã được post";

var TXTDeleteSuccess = 'Xóa thành công';
var TXTNolineSelect = 'Không có dòng nào được chọn!';
var TXTConfirm = 'Xác nhận';
var TXTMessage = 'Thông báo';
var TXTConfirmDelete = 'Bạn có muốn xóa?';
var TXTFind = 'Tìm ';
var TXTConfirmSave = 'Bạn nên lưu trước khi vào detail';
var TXTisvalidfield = 'Vui lòng kiểm tra giá trị trong <b > "{0}" ̣</b>!';
var TXTConfirmPost = 'Bạn có muốn post đơn hàng?';

